package model

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId           int    `gorm:"type:int" json:"userId"`
	OrderSn          string `gorm:"type:varchar(50)" json:"orderSn"`
	Amount           int    `gorm:"type:int" json:"amount"`
	Status           int    `gorm:"type:int" json:"status"`
	PayType          int    `gorm:"type:int" json:"payType"`
	PayTime          int    `gorm:"type:int" json:"payTime"`
	MemberExpireTime int    `gorm:"type:int" json:"memberExpireTime"`
}

func (o *Order) IsOrder(db *gorm.DB, orderSn string) error {
	return db.Where("order_sn = ?", orderSn).First(&o).Error
}
func (o *Order) CreateOrder(db *gorm.DB) error {
	return db.Create(&o).Error
}

func (o *Order) UpdateOrderStatus(db *gorm.DB, orderSn string, status int) error {
	return db.Model(&o).Where("order_sn = ?", orderSn).Update("status", status).Error
}
